package top.jingles.tools.deploytool.entity;

import lombok.Data;
import top.jingles.tools.deploytool.entity.JarInfo.JarType;

@Data
public class JarList {
    String classifier;
    JarInfo normalJar;
    JarInfo javadocJar;
    JarInfo sourcesJar;
    JarInfo testsJar;

    public JarList() {
        classifier = "";
        normalJar = javadocJar = sourcesJar = testsJar = null;
    }

    public void addJar(final JarInfo jar) {
        classifier = jar.getClassifier();
        if (jar.getType() == JarType.normal) {
            normalJar = jar;
        } else if (jar.getType() == JarType.javadoc) {
            javadocJar = jar;
        } else if (jar.getType() == JarType.sources) {
            sourcesJar = jar;
        } else if (jar.getType() == JarType.tests) {
            testsJar = jar;
        }
    }

    public boolean hasJar() {
        return normalJar != null || javadocJar != null || sourcesJar != null || testsJar != null;
    }

    public String toJSONString() {
        StringBuilder sb = new StringBuilder();
        sb.append("{\"classifier\": \"")
            .append(classifier)
            .append("\", \"jar\": ")
            .append(normalJar)
            .append("\", \"javaDocJar\": ")
            .append(javadocJar)
            .append("\", \"sourceJar\": ")
            .append(sourcesJar)
            .append("\", \"testsJar\": ")
            .append(testsJar)
            .append("\"}");
        return sb.toString();
    }
}
